<?php
//屏蔽掉错误 ：比如没有定义的也可以正常使用
error_reporting(7);

//配置返回资料是否自动加入反斜线当溢出字符，设置为0关闭该功能
@ set_magic_quotes_runtime(0);
$time = explode(" ", microtime());
$time_start = $time[0] + $time[1];
define("SYS_TIME_START", $time_start);
unset ($time_start, $time);
if (function_exists("memory_get_usage") && !defined("SYS_MEMORY_START")) {
	define("SYS_MEMORY_START", memory_get_usage());
}
if (!defined('PHP5')) {
	define('PHP5', (PHP_VERSION >= 5));
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
	define('LF', "\r\n");
} else {
	define('LF', "\n");
}


if(!isset($_SERVER["HTTP_REFERER"]))
{
$_SERVER["HTTP_REFERER"] ='';
}
if(!isset($HTTP_SERVER_VARS["HTTP_REFERER"]))
{
$HTTP_SERVER_VARS["HTTP_REFERER"] ='';
}

$php_self_temp = $_SERVER['PHP_SELF'] ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME'];
$_SERVER['QUERY_STRING'] && $php_self_temp .= "?".$_SERVER['QUERY_STRING'];
$php_self =$_SERVER['REQUEST_URI']?$_SERVER['REQUEST_URI']:$php_self_temp;
$http_host =$_SERVER['HTTP_HOST']?$_SERVER['HTTP_HOST']:$HTTP_SERVER_VARS['HTTP_HOST'];
$web_url='http://'.$http_host.$php_self;
$from_url=$_SERVER["HTTP_REFERER"]?$_SERVER["HTTP_REFERER"]:$HTTP_SERVER_VARS["HTTP_REFERER"];

define('WEB_URL',$web_url);
define('FROM_URL',$from_url);
unset($GLOBALS,$http_host,$php_self,$php_self_temp,$web_url,$from_url);
define('ROLE_Y_ID', 'admin:1|scup:1|company:1'); //默认用户组编号,游客组

define('ROLE_P_ID', 'admin:3|scup:3|company:3'); //默认用户组编号,普通用户组

define('ROLE_V_ID', 'admin:2|scup:2|company:2'); //超级管理员用户组

define('ROLE_CON_FILE', 'admin|scup|company'); //用户组控制权限的包名

define('VIEW_CHARSET', 'utf-8'); //网页编码

define('IS_DEBUG', '0'); //是否开启网站错误信息显示,0表示否，1表示开启

class SCup {
	var $SCup_view_root = null; //视图层文件路径

	var $SCup_app_root = null; //逻辑层文件路径

	var $SCup_model_root = null; //控制层文件路径

	var $SCup_filter_root = null; //过滤层文件路径   

	var $SCup_filter_app = null;

	var $SCup_compiled_root = null; //编译后文件路径

	var $SCup_caches_root = null; //缓存文件路径   

	var $SCup_app_name = "default"; //默认使用的控制层文件名

	var $SCup_act_name = "index"; //默认执行的动作名
	
	var $SCup_app = NULL; //逻辑层实体

	var $SCup_view = NULL; //视图层实体

	var $SCup_act = NULL; //执行的动作实体 

	var $SCup_message = NULL; //提示，错误，警告信息实体

	var $user_power_array_file = NULL; //用户权限控制文件数组

	var $SCup_DB = null; //连接数据库实体

	var $SCup_user_session = NULL; //用户session实体

	var $SCup_user_msg = array (); //用户所以信息

	var $SCup_user = null; //用户信息实体   

	var $SCup_user_checking = false; //用户登入验证

	var $SCup_name = 'scup'; //此应用包的名字

	var $SCup_nav = NULL; //网站导航实体

	var $SCup_category = NULL; //网站分类实体

	var $SCup_module_list_data = NULL; //网站模块数据
	
	var $SCup_module_appname = NULL; //网站模块app名
		
	var $SCup_module_table_id = 0; //网站模块表标号
		
	var $SCup_default_module_appname = "content"; //网站模块默认调用的app名
	
	var $SCup_nav_file = NULL;	
	
	var $SCup_user_power = NULL;	
	

	function __construct($config = array ()) {

		$this->SCup($config);

	}

	function SCup($config) {
		$this->SCup_name = $config['SCup_name'];

        if(defined("VIEW_TYPE_DEFAULT"))
		{
		$this->SCup_view_root = $config['view_root'] . '/' . VIEW_TYPE_DEFAULT;	
		$this->SCup_compiled_root = $config['compiled_root'] . '/' . VIEW_TYPE_DEFAULT;

		$this->SCup_caches_root = $config['caches_root'] . '/' . VIEW_TYPE_DEFAULT;			

		}else
		{
		$this->SCup_view_root = $config['view_root'] . '/' . VIEW_TYPE;
		
		$this->SCup_compiled_root = $config['compiled_root'] . '/' . VIEW_TYPE;

		$this->SCup_caches_root = $config['caches_root'] . '/' . VIEW_TYPE;	
		}

		$this->SCup_app_root = $config['app_root'];

		$this->SCup_filter_root = $config['filter_root'];

		$this->SCup_model_root = $config['model_root'];

		$this->SCup_app_name = $config['default_app'] ? $config['default_app'] : 'default';

		$this->SCup_act_name = $config['default_act'] ? $config['default_act'] : 'index';

		$this->user_power_file = $config['user_power_file'];

		if (ENABLED_GZIP) {
			ob_start('ob_gzhandler');
		} else {
			ob_start();
		}

		//加载核心基类文件
		if (!empty ($config['core_libs'])) {
			foreach ($config['core_libs'] as $lib) {
				require ($lib);
			}
		}

		//加载其他基础文件
		if (!empty ($config['external_libs'])) {
			foreach ($config['external_libs'] as $lib) {
				require ($lib);
			}
		}
        if(isset($GLOBALS['SCup']))
		{
		unset ($GLOBALS['SCup']);		
		}
        if ( PHP5 ) {
		    $GLOBALS['SCup'] = $this;                        
        }else {
            $GLOBALS['SCup'] = & $this;
        }		

		
	}

	function Run() {
	    //禁止ip登入
		if(LIMIT_IP_FILEDIR && limit_ip())
		{
		exit ('LIMIT IP');
		}	
		//加载系统语言包及该文件的语言包
		$lang = new Lang();
		$lang->_get_lang('system');

		//产生视图实体
		$this->_get_view();

		//判断是否关闭系统
		if ((!SYSTEM_OPEN) && ($this->SCup_name != 'admin')) {
			exit (SYSTEM_OPEN_REASON);

		}

		if (SYSTEM_URL_REWRITE) {
			//从新得到get数据，用于静态网页，和伪静态网页
			$this->SCup_view->_re_get_url();
		}

		$this->SCup_app_name = !empty ($_GET['app']) ? trim($_GET['app']) : $this->SCup_app_name;
		$this->SCup_act_name = !empty ($_GET['act']) ? trim($_GET['act']) : $this->SCup_act_name;

		$app = $this->SCup_app_name;
		$act = $this->SCup_act_name;

		//过滤get参数和post参数及cookie参数
		$filter_file = $this->SCup_filter_root . "/{$app}.{$act}.flt.php";
		if (is_file($filter_file)) {
		 $this->SCup_filter_app = new Flt();
		} else {
		 $this->SCup_filter_app = new Filter();
		}

		//连接数据库
		$this->_get_db();

		//验证用户登入情况及得到部分用户信息	
		$this->_init_session();
		if(SESSION_USERS_COUNT&&$this->SCup_user_session->get_users_count()>SESSION_USERS_COUNT)
		{
         exit('User Count more '.SESSION_USERS_COUNT);
		}		
        define('LOGIN_ICON',$GLOBALS['SCup']->SCup_user_checking);

		//用户权限验证及控制
		if(!isset($this->usermsg['data']['role_id']))
		{
		  $this->usermsg['data']['role_id'] = ROLE_Y_ID;
		}
		$role_array = role_deal($this->usermsg['data']['role_id']);		
		$role_id = $role_array[$GLOBALS['SCup']->SCup_name];
/*		$this->user_power_file = $this->user_power_file . $GLOBALS['SCup']->SCup_name .'_'.$role_id.'.power.php';*/
		$role_array = role_deal($this->usermsg['data']['role_id']);		
		$GLOBALS['SCup']->SCup_user_power = new UserPower($this->user_power_array_file, $this->SCup_user_msg);
		$GLOBALS['SCup']->SCup_user_power->Power($app, $act);
			
        if($GLOBALS['SCup']->SCup_user_msg['data']['view_start_or_stop'])
		{
		define('VIEW_MANAGE',ROOT_PATH . '/temp/viewmanange/scup/' . VIEW_TYPE);
		$this->SCup_compiled_root = VIEW_MANAGE;
		$this->SCup_view->compile_dir = VIEW_MANAGE;
		$this->SCup_view->view_start_or_stop = true;				
		}
/* 		if ( defined("IS_PHPSCUP_ADMIN") && isset($this->SCup_user_msg['data']['user_name']) && isset($this->SCup_user_msg['user_id'])) {
			admin_logs($this->SCup_user_msg['data']['user_name'],$this->SCup_user_msg['user_id']);
		} */
		$app_file = $this->SCup_app_root . "/{$app}.app.php";
		if (!is_file($app_file)) 
		{
		    $module_list_data = & $this->_get_module_list_data();
		    if(is_array($module_list_data)&& isset($module_list_data[$app]))
			{
			  $this->SCup_module_appname = $app;
			  $this->SCup_module_table_id = $module_list_data[$app]['id'];
			  $app = $this->SCup_default_module_appname;
			  $this->SCup_app_name = $app; 
		      $app_file = $this->SCup_app_root . "/{$app}.app.php";
			  if (!is_file($app_file)) 
		      {	
			   exit ('Missing controller');			  
			  }		  
			}
			else
			{
			exit ('Missing controller');			
			}

		}	
		$this->start_app_run($GLOBALS['SCup']->SCup_name,$app,$act,$this->SCup_module_table_id,$this->SCup_module_appname);
		//产生控制器 
		require ($app_file);
		$app_class_name = ucfirst($app) . 'App';
		//实例化控制器		 
		$GLOBALS['SCup']->SCup_app = new $app_class_name ();
		$GLOBALS['SCup']->SCup_app->do_action($act);
		$GLOBALS['SCup']->SCup_app->destruct();
		$this->end_app_run($GLOBALS['SCup']->SCup_name,$app,$act,$this->SCup_module_table_id,$this->SCup_module_appname);
		$this->_destruct();
		
	}

	//产生数据库实体	
	function & _get_db() {
		if ($this->SCup_DB == null) {
			require (ROOT_PATH . '/lib/sql/' . DB_TYPE . '.lib.php');
			$data_class_name = 'SCup_' . DB_TYPE;
			$this->SCup_DB = new $data_class_name ();
			$this->SCup_DB->connect();

		}

		return $this->SCup_DB;

	}

	//提示，错误，警告信息实体	
	function & _get_message($array = array ()) {
		if ($this->SCup_message == null) {
			$this->SCup_message = new MessageBase($array);
		}

		return $this->SCup_message;
	}

	//得到用户信息	
	function _init_session() {
		if ($this->SCup_user_session == null) {
			if (SYSTEM_MYSQL_SESSION) {
				require (ROOT_PATH . '/lib/session/mysession.lib.php');
				$this->SCup_user_session = new SCup_session(get_table_name('sessions'));
			} else {
				require (ROOT_PATH . '/lib/session/session.lib.php');
				$this->SCup_user_session = new SCup_session();
			}

		}

		return $this->SCup_user_msg;
	}

	//
	function & _get_module_list_data() {
		if ($this->SCup_module_list_data == NULL) 
		{
		 $this->SCup_module_list_data = include (ROOT_PATH . '/data/module/module_list.php');
		}

		return $this->SCup_module_list_data;
	}


	//得到用户信息	
	function _get_nav($filename = '', $lang = '') {
		if ($this->SCup_nav == null) {
			require (ROOT_PATH . '/lib/nav.lib.php');
			$this->SCup_nav = new Nav($filename, $lang);
		}

		return $this->SCup_nav;
	}

	//得到用户信息	
	function _get_user() {
		if ($this->SCup_user == null) {
			require (ROOT_PATH . '/lib/passports/' . USER_TYPE . '.php');
			$user_msg_class_name = 'SCup_' . ucfirst(USER_TYPE);
			$this->SCup_user = new $user_msg_class_name ();

		}

		return $this->SCup_user;
	}

    function _get_city_data()
    {
   	   return include(ROOT_PATH . '/data/city/city_area.php');	  	
    }	
		
	
	function _get_category() {
		if ($this->SCup_category == null) {
			require (ROOT_PATH . '/lib/category.lib.php');
			$this->SCup_category = new Category();
		}

		return $this->SCup_category;
	}

	function _get_category_data($type = '') 
	{

	    if(is_file(ROOT_PATH . '/data/category/category_' . $type . '.php'))
		{
		return include (ROOT_PATH . '/data/category/category_' . $type . '.php');
	    }
		else
		{
		write_file(ROOT_PATH . '/data/category/category_' . $type . '.php',' ');
		return array();
		}	    
	}

	//产生视图实体	
	function & _get_view() {
		if ($this->SCup_view == null) {
			$this->SCup_view = new scupView();
			$this->_init_view();
		}
		return $this->SCup_view;
	}

	//初始化视图实体
	function _init_view() {
		$this->SCup_view->template_dir = $this->SCup_view_root;
		$this->SCup_view->cache_dir = $this->SCup_caches_root;
		$this->SCup_view->compile_dir = $this->SCup_compiled_root;
		$this->SCup_view->widget_dir = ROOT_PATH . '/' . $this->SCup_name . '/widget';
	}


    function start_app_run($scup='',$app='',$act='',$table_id = 0,$c_app='') 
	{
	   if(empty($scup))return false;       
	   if(empty($app))return false;
	   if(empty($act))return false;
	   if($c_app){ $app=$c_app;}
	   $logicfilename = ROOT_PATH . '/'.$scup.'/applogic/'.$app.'.logic.start.php'; 
	   if(file_exists($logicfilename) === true && is_file($logicfilename))
	   {
	        include_once(ROOT_PATH . '/scupcore/app.logic.base.php');	 
		    include($logicfilename); 		   
	        $logic_app_class_name = ucfirst($app) . 'StartLogicApp';	 
	        $logic_app = new $logic_app_class_name ($table_id,$app);
	        $logic_app->do_action($act);			   
	   }else
	   {
	        return false;
	   }				
       return true;
	   	
    }
    function end_app_run($scup='',$app='',$act='',$table_id = 0,$c_app='') 
	{
	   if(empty($scup))return false;       
	   if(empty($app))return false;
	   if(empty($act))return false;
	   if($c_app){ $app=$c_app;}
	   $logicfilename = ROOT_PATH . '/'.$scup.'/applogic/'.$app.'.logic.end.php';		   
	   if(file_exists($logicfilename) === true && is_file($logicfilename))
	   {
	        include_once(ROOT_PATH . '/scupcore/app.logic.base.php');	 
		    include($logicfilename); 	   
	        $logic_app_class_name = ucfirst($app) . 'EndLogicApp';	 
	        $logic_app = new $logic_app_class_name ($table_id,$app);
	        $logic_app->do_action($act);			   
	   }else
	   {
	        return false;
	   }			
       return true;
	   	
    }


	function _destruct() {
	    $this->_integral();
		//ob_end_flush();默认情况下效果与此函数一样，ob_end_flush ：发送内部缓冲区的内容到浏览器，并且关闭输出缓冲区。使用方法：void ob_end_flush(void) 
		// ob_end_clean();删除内部缓冲区的内容，并且关闭内部缓冲区使用方法：void ob_end_clean(void)  

	}
	
	function _integral() {
	    if(!isset($GLOBALS['SCup']->SCup_user_msg['user_id']) || empty($GLOBALS['SCup']->SCup_user_msg['user_id'])){
            return false;
		}  		
 	    $db = & get_db();
		$_prefix = DB_PREFIX;
		$uid = $GLOBALS['SCup']->SCup_user_msg['user_id'];
		$role = $GLOBALS['SCup']->SCup_user_msg['data']['role_id'];
		$datas = $db->get_all('SELECT * FROM '.$_prefix.'integralseting');
		$is = 0;
		$app = !empty ($_GET['app']) ? trim($_GET['app']) : $this->SCup_app_name;
		$act = !empty ($_GET['act']) ? trim($_GET['act']) : $this->SCup_act_name;
        foreach($datas as $key =>$data){
		    if((!empty($data['appname'])&& $data['appname']==$app && !empty($data['action']) && $data['action']==$act )
			|| (!empty($data['url']) && strstr(WEB_URL, $data['url'] )) || 
			(!empty($data['power']) && (strstr($data['power'],'u_'.$uid  ) || strstr($data['power'],'r_'.$role  ) )) ){		        
			   $datas = $data ;
			   $is =1;
			   break;
			   
		    }

        }		
	    if($is==0) {
            return false;
        }		
        $type = $datas['type'];
		$integral= $datas['integral'];
		$dataname = $datas['name'];
        if($type==1){
		  $type1 = '-';
		}else{
		  $type1 = '+';
		}
 		$sql="update ".$_prefix."users set integral = integral $type1 $integral where user_id = ".$uid;
		
	    $user = & $GLOBALS['SCup']->_get_user();
		$userdata = $user->get_info($uid ,'user_id');				
		$totaljifeng =$userdata['integral']; 
		
        $jifeng = $integral ;
		if($totaljifeng<$jifeng)
		{
		 $notice = &get_message(array('msg'=>"您的积分数为".$totaljifeng."，请您及时充值！",'url'=>'','title'=>'Notice'));
		 $notice ->display();			
		}		
		        $userid = $uid;
				$user_name = $GLOBALS['SCup']->SCup_user_msg['data']['user_name'];
				$role_id = $role;
        if($type==1){
		  $type = 0;
		  $type2 = '减';
		  $totalintegral = $totaljifeng - $jifeng;
		}else{
		  $type = 1;
		  $type2 = '加';
		  $totalintegral = $totaljifeng + $jifeng;
		}
				$name = '操作：'.$dataname.'，'.$type2.$integral.'个积分';
				$intro = '操作：'.$dataname.'，'.$type2.$integral.'个积分';
				$integral = $jifeng;
				
				$time = time();
			  
		$db->query("INSERT INTO `{$_prefix}integral` ( `userid` , `user_name` , `role_id` , `type` , `name` , `intro` , `integral` , `totalintegral` , `time` ) 
		VALUES ('$userid','$user_name','$role_id','$type','$name','$intro','$integral','$totalintegral','$time')")	;
		return $db->query($sql);      
	}	
	
}


//得到数据库表名
function get_table_name($tablename) {
	return DB_PREFIX . $tablename;
}

//得到某目录下的所有文件夹名及文件名
function get_all_dirname($dirname) {
	$all_dir = array ();
	$lang_dir_handle = opendir($dirname);

	while (($lang_dir = readdir($lang_dir_handle)) !== false) {
		if (!preg_match("/^\./", $lang_dir)) {
			$all_dir[] = $lang_dir;
		}
	}

	closedir($lang_dir_handle);
	return $all_dir;
}

// 得到视图实体
function & get_view() {

	return $GLOBALS['SCup']->_get_view();
}

// 得到数据库连接实体
function & get_db() {
	return $GLOBALS['SCup']->_get_db();
}

// 得到数据库连接实体
function & get_app() {
	return $GLOBALS['SCup']->SCup_app;
}

function & get_model() {
      static $_model;

		if (empty($_model)) {
			$model_file = ROOT_PATH . "/scupcore/model.base.php";
			if (!is_file($model_file)) {
				exit ('Missing BaseModel');
			}
			include_once($model_file);
			$_model = new BaseModel();

		}

		return $_model;
}

function  get_cache($dir='') {
      static $_cache;

		if (!isset($_cache[$dir])) {
			if (!is_file($dir)) 
			{
				return array();
			}
			$_cache[$dir] = include($dir);

		}

		return $_cache[$dir];
}

function  get_icon_cache($dir='') {
      static $_cache;
       $temp = array();
		if (!isset($_cache[$dir])) {
			if (!is_file($dir)) 
			{
				return array();
			}
			$temp = include($dir);
			$_cache[$dir] = $temp['data'];
		}

		return $_cache[$dir];
}
function admin_logs($username,$userid){
    $timestamp = time();
	$onlineip = get_ip();
	$FROMURL = FROM_URL;
	$WEBURL = WEB_URL;
	unset($logdb);
	$logdb[]="$userid\t$username\t$timestamp\t$onlineip\t$FROMURL\t$WEBURL";
	@include(ROOT_PATH."/data/logs/admin_logs.php");
	$writefile="<?php	\r\n";
	$jj=0;
	foreach($logdb AS $key=>$value){
		$jj++;
		$value=addslashes($value);
		$writefile.="\$logdb[]='$value';\r\n";
		if($jj>200){
			break;
		}
	}
	write_file(ROOT_PATH."/data/logs/admin_logs.php",$writefile);
}
function  Page_And_S_Sql_Exe($iconname,$param = array (
		'table' => '',
		'fields' => '*',
		'conditions' => '',
		'order' => '',
		'limit' => '',
		'return' => 'all',
		'url' => ''
	),$cache_lifetime = 0) {
	    extract($param, EXTR_SKIP);	
		if ($cache_lifetime>0) {
		    $app_name = !empty ($_GET['app']) ? trim($_GET['app']) : 'default';
		    $act_name = !empty ($_GET['act']) ? trim($_GET['act']) : 'index';
		    if(isset($_GET['cat'])) {
		        $cat =  intval(trim($_GET['cat'])) ;
		    }
		    if (isset($GLOBALS['catid'])) {
                $cat =  intval($GLOBALS['catid']);
		    } 
		    if (isset($GLOBALS['cat'])) {
                $cat =  intval($GLOBALS['cat']);
		    } 			
		    $id = intval(trim($_GET['id'])) ;
		    $dir = ROOT_PATH . '/data/icondatacache/'.$app_name . '/' . $act_name .'/' . $cat .'/'. $id .'/' ;
		    $file = $dir. $iconname .'.php';
		    $nowtime = time();
		    $cache_time = @ filemtime($file);
		    if (is_file($file) && ($nowtime - $cache_lifetime <= $cache_time)) {
                return @include($file);
		    }
		    if (!file_exists($dir)) {
			    get_dir($dir);
		    }		
		}			
        $data = get_model()->Page_And_S_Sql_Exe(array("table" => $table,"fields" => $fields,"conditions" => $conditions,"order" => $order,"limit" => $limit,"return" => "all","url" =>$url)) ;
		if ($cache_lifetime>0) {		
	        write_file($file, "<?php \nreturn " . var_export($data , true) . ";\n?>");
		}		
        return $data;		
}


function icon_power_limit($powerlimit_str='') 
{
    $icon = '' ;
	$tof = '1';
	$temp = $temp1 = $temp2 = array();	
	$temp = explode("||",$powerlimit_str);			
    $temp = del_empty_var($temp);
    foreach($temp as $key => $value)
	{
		 $temp1 = explode("&&",$value);
         $temp1 = del_empty_var($temp1);		      
	     $temp2[$key] = $temp1;
	}
	foreach($temp2 as $key1=>$value1)
	{
	   foreach($value1 as $key2=>$value2)
	   {
	      $temp2[$key1][$key2] = icon_power_limit_str($value2);
	      $icon .= $temp2[$key1][$key2].' && ';			  
	   }
	   $icon = substr($icon, 0,-3);
	   $icon .= ' || ';	
	}
	$icon = substr($icon, 0,-3);		
    eval("\$tof = ( ".$icon." ) ;");	
    return $tof;
}

function icon_power_limit_str($powerlimit_str='') 
{
	$temp = $temp1 = $temp2 = array();	
	$temp = explode("-",$powerlimit_str);			
    $temp = del_empty_var($temp);
	$num = count($temp);
		
	$temp1[0] = $temp[0];	
	$temp1[1] = $temp[1];
	$temp1[2] = $temp[2];	
	if($num==2)
	{
	   $temp1[0] = 'scup';	
	   $temp1[1] = $temp[0];
	   $temp1[2] = $temp[1];	   
	}	
	$temp2 = explode(":",$temp1[1]);	
	if(!isset($temp2[1])||empty($temp2[1]))
	{
	   $temp1[1] = $temp2[0].':0';	
	}else
	{
	   $temp1[1] = $temp2[0].':'.$temp2[1];		
	}
				
    return $GLOBALS['SCup']->SCup_user_power->IconPowerLimit($temp1);
}

function icon_active($activetime,$activebefore,$activeperiod,$activeafter) 
{        
     if($activetime)
	 {
		    $temp = $temp1 = array();	
		    $temp = explode(",",$activetime);			
            $temp = del_empty_var($temp);
			$now_time = time();		
		    $before_time = strtotime($temp[0]);
		    $after_time = strtotime($temp[1]);
					
			if(($before_time>$now_time)&&$activebefore)
			{
			   return get_view()->__active($activebefore,'before');
			}
			if(($after_time<$now_time)&&$activeafter)
			{
			   return get_view()->__active($activeafter,'after');
			}			
			if(($after_time>=$now_time&&$before_time<=$now_time)&&activeperiod)
			{
			   return get_view()->__active($activeperiod,'period');
			}		 
	 }else
	 {

			if($activebefore)
			{
			   return  get_view()->__active($activebefore,'before');
			}
			if($activeafter)
			{
			   return get_view()->__active($activeafter,'after');
			}		 
	      
	 } 

}

// 得到应用包的名字

function get_scup_name() {

	return $GLOBALS['SCup']->SCup_name;
}

function & get_module_list_data() 
{
	  return $GLOBALS['SCup']->SCup_module_list_data;
}

function  get_form_list_data() 
{
	  return include (ROOT_PATH . '/data/form/form_list.php');
}
function  get_usertype_list_data() 
{
	  return include (ROOT_PATH . '/data/usertype/usertype_list.php');
}


//得到提示，错误，警告信息实体

function & get_message($array = array ()) {
	return $GLOBALS['SCup']->_get_message($array);
}

//用户组字符串解析
function role_deal($str) {
	$array = array ();
	$str_array = explode('|', $str);
	foreach ($str_array as $key => $value) {
		if ($value) {
			$str_v = explode(':', $value);
			$array[$str_v[0]] = $str_v[1];

		}

	}

	return $array;

}

function sys_debug() {

	if (!defined("SYS_TIME_START")) {
		return false;
	}
	if (!defined("SYS_MEMORY_START") || !function_exists("memory_get_usage")) {
		return false;
	}
	$time = explode(" ", microtime());
	$end_time = $time[0] + $time[1];
	$time_used = round(($end_time -SYS_TIME_START), 5);

	$mysql_count = $GLOBALS['SCup']->_get_db()->querynum;
	$mysql_times = $GLOBALS['SCup']->_get_db()->querytime;

	$end = memory_get_usage();
	$used = $end -SYS_MEMORY_START;
	if ($used <= 1024) {
		$used = "1 KB";
	}
	elseif ($used > 1024 && $used < (1024 * 1024)) {
		$used = round(($used / 1024), 4) . " KB";
	} else {
		$used = round(($used / (1024 * 1024)), 4) . " MB";
	}
	$memory = $used;
	$msg = "Processed in " . $time_used . " second(s), mysql: " . $mysql_count . " queries";
	$msg .= ", " . $mysql_times . " second(s)";
	if ($memory) {
		$msg .= ", memory: " . $memory;
	}

	return $msg;
}
?>